//index.js
//获取应用实例
const app = getApp();
let pNo = 1, pageNo=1;
const getToken = require('../../utils/get_token.js');
const QQMapWX = require('../../utils/qqmap-wx-jssdk.min.js');
// 实例化API核心类
const qqmapsdk = new QQMapWX({
  key: 'E3PBZ-LFJCU-QT6VK-BBI5V-BJH3V-QKBTC'
});
let memberId='',hebiRedFlag='';

const ckToken = async (that) => {//token确认
  let nTime = Math.floor(new Date().getTime() / 1000);
  let oldTime = wx.getStorageSync('ntime') || 0;
  if (nTime < oldTime)//现在的时间小于到期时间
  {
    thou(that);
  } else {
    await getToken.getToken();
    thou(that);
  }
}
const thou = (that) => {//token没有失效时执行的代码
   getTopClass(that);
   banner(that);
   indexList(that, pNo, that.data.mainTab)//初始加载
   hotList(that);
   if(hebiRedFlag==1){
    goodnList(that);
  }
  goodList(that);
}
const goodnList = (that) => {//新人列表
  let params = ['shop/pingTuan/subjectValueBestGoodsList', {'pageNo': 1, 'pageSize': 10, 'isBest': 1,'subjectValue':0 }]
  getToken.getData(function (res) {
    let data = res.data;
    if(data.rows.length>0)
    {
      for(let i=0;i<data.rows.length;i++)
      {   
        data.rows[i].goodsImg='https://www.globalhexi.com/'+data.rows[i].goodsImg;
        data.rows[i].intPrice = (data.rows[i].intPrice / 100).toFixed(2);
        data.rows[i].intPinPrice = (data.rows[i].intPinPrice/100).toFixed(2);
        data.rows[i].newShow=true;
        that.data.arr.push(data.rows[i]);
      }		  	 
    } 
    that.setData({arr: that.data.arr})
  }, ...params)

};
const goodList = (that) => {//商品列表
let params = ['shop/pingTuan/subjectValueBestGoodsList', {'pageNo': 1, 'pageSize': 10, 'isBest': 0,'subjectValue':108 }]
  getToken.getData(function (res) {
    let data = res.data;
    if(data.rows.length>0)
    {
      for(let i=0;i<data.rows.length;i++)
      {   
        data.rows[i].goodsImg='https://www.globalhexi.com/'+data.rows[i].goodsImg;
        data.rows[i].intPrice = (data.rows[i].intPrice / 100).toFixed(2);
        data.rows[i].intPinPrice = (data.rows[i].intPinPrice/100).toFixed(2);
        that.data.arr.push(data.rows[i]);
      }		  	 
    } 
    let tlength=that.data.arr.length;
    let Iindex=Math.ceil(tlength/3);

    for(let j=0;j<Iindex;j++){
      that.data.arrNew[j]=[];
      let nowa=j*3;
      let nowb=j*3+1;
      let nowc=j*3+2;
      if(nowa<tlength){
        that.data.arrNew[j].push(that.data.arr[nowa])
      }
      if(nowb<tlength){
        that.data.arrNew[j].push(that.data.arr[nowb])
      }
      if(nowc<tlength){
        that.data.arrNew[j].push(that.data.arr[nowc])
      }
    }
    that.setData({arrNew: that.data.arrNew})
    console.log(that.data.arrNew)
  }, ...params)
};
const getTopClass=function(that){//获取分类
  let params = [ 'shop/pptIco/getDictionaryValueList', {"dicType":"SLP_INDEX_TOP_CATEGRAY"}]
  getToken.getData(function (res) {
    console.log(res.data)	  	
    let data=res.data;   			 
		that.data.tList=[{'showName':'首页','show':true,'id':'11111','mark':'11111,11111'}];
		for(let i=0;i<data.rows.length;i++)
		{
		  that.data.tList.push(data.rows[i]); 
		}  
    that.setData({
      tList: that.data.tList
    })
  }, ...params)
}
const getSclass=function(that,Aid){//二级分类
  let params = [ 'shop/pptIco/lorB', {"A":Aid}]
  getToken.getData(function (res) {
    console.log(res.data)	  	
    let data=res.data;   			 
    if(data.B!='0')
    {
      that.data.sList=data.A[Aid];
    }else{
      that.data.sList=[];  
    }
    that.setData({
      sList: that.data.sList
    })
  }, ...params)
}
const banner = function (that) {//轮播图SLP_TOP_AD/活动页SLP_INDEX_ACTIVE_PAGE_ENTRY/下面的分类HP_SQP_FL
  let params = [ 'shop/pptIco/lorB', { "A": "SLP_TOP_AD,HP_SQP_FL,SLP_INDEX_ACTIVE_PAGE_ENTRY,SLP_ING_MEMBER_NUM"}]
  getToken.getData(function (res) {
    that.data.imgUrls = res.data.A.SLP_TOP_AD;
    that.data.cLength = that.data.imgUrls.length;
    res.data.A.HP_SQP_FL[0].K = '';
    that.data.eList.push({'name':'大家都喜欢的坚果零食','img':'../../image/i_24.png','img1':'','img2':'','id':res.data.A.HP_SQP_FL[1].K,'kid':`${res.data.A.HP_SQP_FL[1].D}_BG`,'kin':res.data.A.HP_SQP_FL[1].E});
    that.data.eList.push({'name':'让居家生活多点乐趣','img':'../../image/i_25.png','img1':'','img2':'','id':res.data.A.HP_SQP_FL[2].K,'kid':`${res.data.A.HP_SQP_FL[2].D}_BG`,'kin':res.data.A.HP_SQP_FL[2].E});
	  that.data.activeImg='http://www.globalhexi.com/'+res.data.A.SLP_INDEX_ACTIVE_PAGE_ENTRY[0].I;//活动页图片
	  that.data.activeUrl=res.data.A.SLP_INDEX_ACTIVE_PAGE_ENTRY[0].K;//活动页路径
	  that.data.pNUm=res.data.A.SLP_ING_MEMBER_NUM[0].F;//正在拼团人数
    that.setData({
      imgUrls: that.data.imgUrls,
      cLength: that.data.cLength,
      activeImg: that.data.activeImg,
      pNUm: that.data.pNUm,
    })
    imggList(that,that.data.eList[0].id,0);
    imggList(that,that.data.eList[1].id,1);
  }, ...params)
}
const hotList = function (that) {//热拼榜
  let params = [ 'shop/pingTuan/hotHuoPinGoods', {'memberId': memberId}]
  getToken.getData(function (res) {
    console.log(res.data)
    let rows = res.data.rows;
    for (let i = 0; i < rows.length; i++) {
     // rows[i].goodsImageStore = rows[i].goodsImageStore.substring(1, rows[i].goodsImageStore.length - 1);
      rows[i].goodsImageStore = JSON.parse(rows[i].goodsImageStore);
      rows[i].img = 'https://www.globalhexi.com/' + rows[i].goodsImageStore[0].path + '/small/' + rows[i].goodsImageStore[0].id + '.jpg';
      rows[i].intPinPrice = (rows[i].intPinPrice / 100).toFixed(2);
    }
    that.data.hList = rows;
    that.setData({
      hList: that.data.hList
    })
  }, ...params)
}
const indexList = (that, pNo, brand) => {//商品列表
  if (that.data.boolT)
  {
    that.setData({hidden: false})
    that.data.boolT = false;
    let params = ['shop/pingTuan/indexQ99G5', { 'pageNo': pNo, 'isType': 5, 'categoryId': brand }]
    getToken.getData(function (res) {
      console.log(res.data)
      let data = res.data;
      if (data.rows.length > 0) {
        for (let i = 0; i < data.rows.length; i++) {
         // data.rows[i].goodsImageStore = data.rows[i].goodsImageStore.substring(1, data.rows[i].goodsImageStore.length - 1);
          data.rows[i].goodsImageStore = JSON.parse(data.rows[i].goodsImageStore);
          data.rows[i].img = 'https://www.globalhexi.com/' + data.rows[i].goodsImageStore[0].path + '/small/' + data.rows[i].goodsImageStore[0].id + '.jpg';
          data.rows[i].intPinPrice = (data.rows[i].intPinPrice / 100).toFixed(2);
          data.rows[i].intPrice = (data.rows[i].intPrice / 100).toFixed(2);
          that.data.list.push(data.rows[i]);
        }
      }
      setTimeout(function () {
        that.data.boolT = true;
        that.setData({
          list: that.data.list,
          hidden: true
        })
      }, 500)
    }, ...params)
  }
};
const cheNewList = async (that) => {//token确认
  let nTime = Math.floor(new Date().getTime() / 1000);
  let oldTime = wx.getStorageSync('ntime') || 0;
  if (nTime < oldTime)//现在的时间小于到期时间
  {
    //newList(that);
  } else {
    await getToken.getToken();
   // newList(that);
  }
}
const newList = (that) => {//新人列表
    let params = ['shop/pingTuan/subjectValueBestGoodsList', {'pageNo': 1, 'pageSize': 10, 'isBest': 1,'subjectValue':0 }]
    getToken.getData(function (res) {
      console.log(res.data)
      let data = res.data;
      if (data.rows.length > 0) {
        for (let i = 0; i < data.rows.length; i++) {
          data.rows[i].goodsImg='https://www.globalhexi.com/'+data.rows[i].goodsImg;
          data.rows[i].intPrice = (data.rows[i].intPrice / 100).toFixed(2);
          data.rows[i].intPinPrice = (data.rows[i].intPinPrice/100).toFixed(2);
          that.data.nList.push(data.rows[i]);
        }
      } 
      that.setData({nList: that.data.nList,xShow:true})
    }, ...params)
  
};
// const pingList = (that, pageNo) => {//获取正在拼团列表
//   if (that.data.boolT)
//   {
//     that.setData({ hidden: false})
//     that.data.boolT = false;
//     let params = ['shop/pingTuan/getPinTuanIngBytza', { 'pageNo': pageNo, 'memberId': memberId, 'address': ''}]
//     getToken.getData(function (res) {
//       let data = res.data;
//       console.log(data);
//       //  data.rows[i].mobile = data.rows[i].mobile.substring(0, 3) + '****' + data.rows[i].mobile.substring(7, 12);
//       if (data.rows.length > 0) {
//         that.data.glist=data.rows[0].tuanList;
//         that.data.glist.forEach(ele => {
//           ele.goodsImage=`http://www.globalhexi.com/${ele.goodsImage}`;
//           ele.intHebiPrice=(ele.intHebiPrice/100).toFixed(2);
//         });
//       }
//       console.log(that.data.glist)
//       setTimeout(function () {
//         that.data.boolT = true;
//         that.setData({
//           glist: that.data.glist,
//           hidden: true
//         })
//       }, 500)
//     }, ...params)
//   }
// };
const pingpeo = (that) => {//获取正在拼团列表
    let params = ['shop/pingTuan/getPinTuanIngByMemberId', {'memberId': memberId}]
    getToken.getData(function (res) {
      let data = res.data;
      console.log(data);
      //  data.rows[i].mobile = data.rows[i].mobile.substring(0, 3) + '****' + data.rows[i].mobile.substring(7, 12);
      if (data.flag) {
        that.data.glist=data.tuanList;
        clearInterval(that.data.inset);
        that.data.glist.forEach(ele => {
          ele.goodsImage=`http://www.globalhexi.com/${ele.goodsImage}`;
          ele.price=(ele.price/100).toFixed(2);
          fresh(that,ele.endTimes,ele);
          let mLength=ele.memberLogoList.length;
          ele.memList=[];
          for(let i=0;i<mLength;i++){
            if(i<=3){//最多只添加4个数据
              if(ele.memberLogoList[i].logo.indexOf("http://")==-1)
              {
                ele.memberLogoList[i].logo="http://www.globalhexi.com/"+ele.memberLogoList[i].logo;
              }
              if(mLength<=2){//只有三个人时
                ele.memList.push({'type':1,'name':ele.memberLogoList[i].nickName,'logo':ele.memberLogoList[i].logo}) 
              }else{//加入省略号
                  if(i==1){
                    ele.memList.push({'type':2,'name':ele.memberLogoList[i].nickName,'logo':ele.memberLogoList[i].logo}) 
                  }else{
                    ele.memList.push({'type':1,'name':ele.memberLogoList[i].nickName,'logo':ele.memberLogoList[i].logo}) 
                  }
              }
            }
          }
          ele.memList.push({'type':3,'name':'邀请好友','logo':'../../image/s_31.png'});
        });
        that.setData({glist: that.data.glist})
        that.data.inset=setInterval(function () {
          for (let i = 0; i < that.data.glist.length; i++)
          {
           that.data.glist[i].endTimes--;
            fresh(that, that.data.glist[i].endTimes, that.data.glist[i])
           that.setData({glist: that.data.glist})
          } 
       }, 1000)
      }
      
    }, ...params)
};
const pingList = (that,pageNo) => {//大家都在拼
  if (that.data.boolT)
  {
    that.setData({ hidden: false})
    that.data.boolT = false;
    let params = ['shop/pingTuan/getPinTuanIng', {pageNo,'pageSize':10}]
    getToken.getData(function (res) {
      let data = res.data;
      console.log(data);
      if(pageNo==1){that.data.pList=[];}
      if(data.flag){
        for(let i=0;i<data.rows.length;i++){
          data.rows[i].goodsImage=`http://www.globalhexi.com/${data.rows[i].goodsImage}`;
          data.rows[i].price=(data.rows[i].price/100).toFixed(2);
          if(data.rows[i].memberLogoList.length>0){
             data.rows[i].memList=[];
             let mlength=data.rows[i].memberLogoList.length;
            for(let j=0;j<mlength;j++){
              if(data.rows[i].memberLogoList[j].logo.indexOf("http://")==-1)
              {
                data.rows[i].memberLogoList[j].logo="http://www.globalhexi.com/"+data.rows[i].memberLogoList[j].logo;
              }
              if(mlength>6&&j==0){
                data.rows[i].memList.push({'type':'text','logo':'...'})
              }
              if(j<6){
                data.rows[i].memList.push({'type':'img','logo':data.rows[i].memberLogoList[j].logo})
              }
            }
          }
          that.data.pList.push(data.rows[i]);
        }
      }
      setTimeout(function () {
        that.data.boolT = true;
        that.setData({
          pList: that.data.pList,
          hidden: true
        })
      }, 500)
    }, ...params)
  }
};
const getZList=(that)=>{//获取二级分类列表
  if (that.data.boolT)
  {
    that.setData({hidden: false});
    that.data.boolT = false;
    let params = ['shop/pingTuan/getPinTuanIngByCategoryId', {"pageNo":that.data.cNo,"categoryId":that.data.cid}]
    getToken.getData(function (res) {
      let data = res.data;
      console.log(data);
      if(that.data.cNo==1)
			 {
				  that.data.zList=[];
          if(data.rows.length>0)
            {
              that.data.haveShow=true;
            }else{
              that.data.haveShow=false;
            }
			 } 	   		 
			 if(data.rows.length>0)
			 {
				 for(let i=0;i<data.rows.length;i++)
				 {   
					 data.rows[i].imageStore=JSON.parse(data.rows[i].imageStore);
					 data.rows[i].img='http://www.globalhexi.com/'+data.rows[i].imageStore[0].path+'/small/'+data.rows[i].imageStore[0].id+'.jpg';
					 data.rows[i].intPinPrice=(data.rows[i].intPinPrice/100).toFixed(2);		
					 data.rows[i].intPrice=(data.rows[i].intPrice/100).toFixed(2);	  		
					 that.data.zList.push(data.rows[i]);
				 }
				 that.data.cNo++;
			 }
      setTimeout(function () {
        that.data.boolT = true;
        that.setData({
          zList: that.data.zList,
          haveShow: that.data.haveShow,
          hidden: true
        })
      }, 500)
    }, ...params)
  }
}
const imggList = (that,id,index) => {//商品列表
    let params = ['shop/pingTuan/indexQ99G5', { 'pageNo': 1, 'isType': 5, 'categoryId': id }]
    getToken.getData(function (res) {
      let data = res.data;
      if(data.rows.length>0)
			{
				for(let i=0;i<2;i++)
				{   
					data.rows[i].goodsImageStore=JSON.parse(data.rows[i].goodsImageStore);
					data.rows[i].img='http://www.globalhexi.com/'+data.rows[i].goodsImageStore[0].path+'/small/'+data.rows[i].goodsImageStore[0].id+'.jpg';
        }	
        that.data.eList[index].img1=data.rows[0].img; 
        that.data.eList[index].img2=data.rows[1].img; 	 
      } 
      that.setData({eList: that.data.eList})
    }, ...params)
  
};
const adzo=function(num) {
	if (num < 10)
		return ('0' + num);
	else
		return num;
}
const fresh=function(that,data,dom){
	if (data <= 0) {
		dom.times = '00:00:00';
	} else {
    let h = adzo(parseInt(data / 3600));
    let m = adzo(parseInt((data / 60) % 60));
    let s = adzo(parseInt(data % 60));
		dom.times =`${h}:${m}:${s}`;
	}
}
Page({
  data: {
    statusBarHeight: app.globalData.statusBarHeight,
    keyWord:'',
    indicatorDots: true,
    indicatorC: "#fff",
    indicatorAC: "red",
    current:0,
    cIndex:1,
    cLength:1,
    autoplay: true,
    interval: 4000,
    duration: 500,
    circular: true,
    arr:[],
    arrNew:[],
    tList:[],
    hList:[],
    imgUrls: [],
    tshop:[],
    sList:[],
    zList:[],
    nList:[],
    eList:[],
    pList:[],
    numberList:[{'show':true,'src':'../../image/duoduo.png'},{'show':false,'src':'../../image/duoduo.png'},{'show':true,'src':'../../image/duoduo.png'},{'show':true,'src':'../../image/duoduo.png'},{'show':true,'src':'../../image/s_31.png'}],
    haveShow:true,
    xShow:false,
    activeImg:'',
    pNUm:0,
    wHeight:app.globalData.windowHeight,
    isStopBodyScroll:'auto',
    dShow:false,
    xhShow:false,
    top:0,
    shopShow:false,
    hidden:false,
		endB:false,
		bool:true,
		boolT: true,
    tab:true,
    classShow:false,
    inset:'',
		memberId:'',
    mainTab:'',
    city:'',
    list:[],
    glist:[],
    cid:'',
    cNo:1
  },
  onLoad: function (options) {
    let that = this;
    let shareId=options.shareId||'';
    if(shareId!='')
    {
      wx.setStorageSync('shareId', shareId);
    }
     ckToken(that);
     memberId= wx.getStorageSync('memberId') || '';
     hebiRedFlag= wx.getStorageSync('hebiRedFlag') || '';
     if(memberId==''){//如果没有登录
      that.setData({dShow:true})
    }
    //  if(memberId==''){//如果没有登录
    //     that.setData({
    //       isStopBodyScroll: that.data.wHeight+'px',
    //       dShow:true
    //     })
    //     cheNewList(that);
    // }else{
    //     if(hebiRedFlag==1){//如果是新人
    //       that.setData({isStopBodyScroll: that.data.wHeight+'px',})
    //       cheNewList(that);
    //     }
    // }
      //this.reverseGeocoder();经纬度逆解析
  },
  onShow: function () {
    let that = this;
    that.setData({keyWord:''})
  },
  reverseGeocoder() {/**经纬度逆解析 */
    const that = this;
    wx.getLocation({
      type: 'gcj02',
      success: function (res) {
        var latitude = res.latitude
        var longitude = res.longitude
        qqmapsdk.reverseGeocoder({
          location: {
            latitude: latitude,
            longitude: longitude
          },
          success: function (res) {
            const { city } = res.result.address_component;
            that.setData({
              city,
            })
          },
        });
      },
      fail(res) {

      }
    })
  },
  onSlideChangeEnd:function(e){//轮播图切换
    let that = this;
    that.data.cIndex = e.detail.current+1;
    that.setData({
      cIndex: that.data.cIndex
    })
  },
  changeA:function(e){//点击正在伙拼
    let that = this;
    let cur = e.currentTarget.dataset.bool;
    if (cur)
    {
      pNo = 1;
      that.data.list = [];
      indexList(that, pNo, that.data.mainTab);
    }else{//即将成团
      pageNo = 1;
      pingpeo(that);
      pingList(that, pageNo);  
    }
    that.setData({
      tab: cur,
      shopShow: !cur
    })
  },
  changeList:function(e){
    let that = this;
    let id=e.currentTarget.dataset.id;
    let mark=e.currentTarget.dataset.mark; 
    for(let i=0;i<that.data.tList.length;i++)
    {
      if(id==that.data.tList[i].id)
      {
        that.data.tList[i].show=true;
      }else{
        that.data.tList[i].show=false;
      }
    }
    let mks=mark.split(',');	
    if(id=='11111')
    {
      that.data.classShow=false;
    }else{
      that.data.classShow=true;
     getSclass(that,mks[0]);
      that.data.cid=mks[1];
      that.data.cNo=1;
      getZList(that);
    }
    that.setData({
      tList:that.data.tList,
      classShow:that.data.classShow
    })
  },
  go_eClass:function(e){
    let that = this;
    let id=e.currentTarget.dataset.id;
    for(let i=0;i<that.data.sList.length;i++)
    {
      if(id==that.data.sList[i].K)
      {
        that.data.sList[i].show=true;
      }else{
        that.data.sList[i].show=false;
      }
    }
    that.setData({
      sList:that.data.sList
    })
    that.data.cid=id;
    that.data.cNo=1;
    getZList(that);
  },
  x_close:function(){//关闭新人弹窗
    let that = this;
    that.setData({
      isStopBodyScroll: 'auto',
      xShow: false,
      xhShow:true
    })
  },
  closedl:function(){
    let that = this;
    that.setData({
      dShow: false,
    })
  },
	enter: function (e) {
    let that = this;
    console.log(e.currentTarget.dataset.id)
		if (that.data.boolT) {
			that.data.boolT = false;
			wx.navigateTo({
        url: '../paired_detail/paired_detail?scene=' + e.currentTarget.dataset.id,
				success: function () {
					setTimeout(function () {
						that.data.boolT = true;
					}, 500)
				}
			})
		}
  },
  go_login:function(){
    let that = this;
		if (that.data.boolT) {
      that.data.boolT = false;
			wx.redirectTo({
        url:'../login/login?id=1',
				success: function () {
					setTimeout(function () {that.data.boolT = true;}, 500)
				}
			})
		}
  },
  go_acive:function(e){//去活动页面
    let that = this;
    let id=e.currentTarget.dataset.id;
    let kid=e.currentTarget.dataset.kid;
    let kin=e.currentTarget.dataset.kin;
    if (that.data.boolT) {
      that.data.boolT = false;
      wx.navigateTo({
        url:`../activity/activity?id=${id}&kid=${kid}&kin=${kin}`,
        success: function () {
          setTimeout(function () {
            that.data.boolT = true;
          }, 500)
        }
      })
    }
  },
  go_befit:function(){
    let that = this;
    if (that.data.boolT) {
      that.data.boolT = false;

      if(memberId==''){//如果没有登录
        wx.redirectTo({
          url:'../login/login?id=1',
          success: function () {
            setTimeout(function () {that.data.boolT = true;}, 500)
          }
        })
      }else{
        wx.navigateTo({
          url: '../benefit/benefit',
          success: function () {
            setTimeout(function () { that.data.boolT = true;}, 500)
          }
        })
      }
    }
  },
  go_split:function(e){//去参团页面
    let that = this;
    let id = e.currentTarget.dataset.id;
    let tid = e.currentTarget.dataset.tuanid;
    if (that.data.boolT) {
      that.data.boolT = false;
      wx.navigateTo({
        url: '../tuxedo/tuxedo?id=' + id+'&tuanid='+tid,
        success: function () {
          setTimeout(function () {
            that.data.boolT = true;
          }, 500)
        }
      })
    }
  },
  enterShop: function (e) {
    let that = this;
    if (that.data.boolT) {
      that.data.boolT = false;
      wx.navigateTo({
        url: '../shop/shop?id=' + e.currentTarget.dataset.id,
        success: function () {
          setTimeout(function () {
            that.data.boolT = true;
          }, 500)
        }
      })
    }
  },
  search: function (e) {
    let that = this;
    e.detail.value = e.detail.value.replace(/\s+/g, "");
    if (e.detail.value != '') {
      if (that.data.boolT) {
        that.data.boolT = false;
        wx.navigateTo({
          url: '../search/search?id=' + e.detail.value,
          success: function () {
            setTimeout(function () {
              that.data.boolT = true;
            }, 500)
          }
        })
      }
    }
	},
  /**进入必逛 */
  enterbg: function (e) {
    var that = this;
    if (that.data.boolT) {
      that.data.boolT = false;
      wx.navigateTo({
        url: '../around/around?id=' + e.currentTarget.dataset.id,
        success: function () {
          setTimeout(function () {
            that.data.boolT = true;
          }, 500)
        }
      })
    }
  },
  register: function (e) {
    let that = this;
    this.data.memberId = wx.getStorageSync('memberId');
    if (e.currentTarget.dataset.current == 0) {

    } else if (e.currentTarget.dataset.current == 1) {
      if (this.data.memberId == '') {
        if (that.data.boolT) {
          that.data.boolT = false;
          wx.navigateTo({
            url: '../login/login?id=1',
            success: function () {
              setTimeout(function () {
                that.data.boolT = true;
              }, 500)
            }
          })
        }
      }
    }
  },
  lower:function(){
    
  },
  scroll: function (e) {

  },
	onReachBottom: function () {//上啦加载更多
    let that = this;
    if(that.data.classShow){//二级菜单列表
      getZList(that); 
    }else{
      if (!that.data.tab)//正在伙拼
      {
        pageNo++;
        pingList(that, pageNo);
      } else {
        pNo++;
        indexList(that, pNo, that.data.mainTab);
      }
    }
	},
  // onPullDownRefresh: function (e) {//下拉刷新
  //   let that = this;
  //   wx.showNavigationBarLoading()//加载动画
  //   if(that.data.classShow){//二级菜单列表
  //     that.data.cNo=1;
  //     getZList(that); 
  //   }else{
  //     if (!that.data.tab)//正在伙拼
  //     {
  //       pageNo=1;
  //       that.data.glist=[];
  //       pingList(that, pageNo);
  //     } else {
  //       pNo=1;
  //       that.data.list=[];
  //       indexList(that, pNo, that.data.mainTab);
  //     }
  //   }
  //   setTimeout(function () {
  //     wx.hideNavigationBarLoading()//隐藏动画
  //     wx.stopPullDownRefresh()//停止加载
  //   }, 500)
    
  // },
  onPageScroll: function (e) {//监听页面滚动
    let that = this;
    that.data.top = e.scrollTop;
  },
  onShareAppMessage: function (res) {
    if(res.from === 'button'){
        let fTit=`【仅剩${res.target.dataset.num}个】我${res.target.dataset.price}元拼了${res.target.dataset.name}`;
        let id=res.target.dataset.id;
        let tuanid=res.target.dataset.tuanid;
        return {  
          title: fTit, 
          path:`/pages/tuxedo/tuxedo?id=${id}&tuanid=${tuanid}&shareId=${memberId}`, 
          imageUrl:res.target.dataset.gimg, 
          success: function (res) {}
        }
      
      }
    return {
      title: '拼拼团·省省钱',
      path: '/pages/index/index?shareId='+memberId,
      imageUrl:'http://image.globalhexi.com/oss/img/image/20201231/source/4a9fab0f1d2c448392e856e6696b9943.jpg',
      success: function (res) {
        // 转发成功
      },
      fail: function (res) {
        // 转发失败
      }
    }
  }
})
